<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Mail;

class SendEmails extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'emails:send';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'This is a demo about sending emails to myself';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //$this->info('I am handsome');
        //$this->error('I am not ugly');
        try{
            $user = [
            'email' => '1594989692@qq.com',//一个有效的邮箱接收地址
            'name'  => 'wuxiaobu',
        ];
            $mailTo = '1594989692@qq.com';
            \Mail::send('emails.send', ['user'=>$user], 
                function ($message) use ($mailTo) {
                $message->from(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'));
                $message->to($mailTo);
                $message->subject('This is a demo about sending emails to myself');
            });
            $this->info('Success to send email');exit;
        }
        catch(\Exception $ex){
            $this->error($ex->getMessage());exit;
        }
    }
}
